package com.android.home.adapter.holder;

import android.content.Context;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.appcompat.widget.SwitchCompat;
import com.android.common.base.rv.BaseRvHolder;
import com.android.home.R;
import com.android.home.mvp.model.home.MsgSwitchResponseBean;
import com.android.home.mvp.present.home.HomePresent;

public class MsgNoticeSwitchHolder extends BaseRvHolder<MsgSwitchResponseBean.NoticeSwitchVoListBean>
    implements CompoundButton.OnCheckedChangeListener{

    public static final int TYPE_MSG_NOTICE_SWITCH = MsgNoticeEnterHolder.TYPE_MSG_NOTICE_ENTER + 1;

    private Context mContext;
    private final TextView mTvName;
    private final ImageView mIvIcon;
    private final SwitchCompat mScMsgNotice;

    public MsgNoticeSwitchHolder(View itemView) {
        super(itemView);
        mContext = itemView.getContext();
        mTvName = itemView.findViewById(R.id.tv_name);
        mIvIcon = itemView.findViewById(R.id.iv_icon);
        mScMsgNotice = itemView.findViewById(R.id.sc_msg_notice);
        initEvent();
    }

    private void initEvent(){
        mScMsgNotice.setOnCheckedChangeListener(this);
    }

    @Override
    public void bindData(MsgSwitchResponseBean.NoticeSwitchVoListBean bean, int position) {
        mTvName.setText(bean.getText());
        mIvIcon.setImageResource(bean.getIcon());
        if (HomePresent.SWITCH_STATUS_ON.equals(bean.getSwitchStatus())){
            mScMsgNotice.setChecked(true);
        }else {
            mScMsgNotice.setChecked(false);
        }
    }

    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
        if (null != mSwitchChangedListener && compoundButton.isPressed()){
            mSwitchChangedListener.onSwitchChanged(getBindingAdapterPosition() ,isChecked);
        }
    }
}
